﻿

#include "Test/Timer.h"

#include "Components/TextRenderComponent.h"


ATimer::ATimer()
{
	PrimaryActorTick.bCanEverTick = true;

	TextRenderComponent = CreateDefaultSubobject<UTextRenderComponent>(TEXT("Text"));
	TextRenderComponent->SetupAttachment(RootComponent);
	
}

void ATimer::BeginPlay()
{
	Super::BeginPlay();

	GetWorldTimerManager().SetTimer(TimerHandle, this, &ATimer::TimeDownFunc, 1.0f, true);
}

void ATimer::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void ATimer::TimeDownFunc()
{
	TimeDown--;
	TextRenderComponent->SetText(FText::FromString(FString::FromInt(TimeDown)));
	
	if (TimeDown < 1)
	{
		GetWorldTimerManager().ClearTimer(TimerHandle);
		TimeDownFinish();
	}
}

void ATimer::TimeDownFinish_Implementation()
{
	TextRenderComponent->SetText(FText::FromString(TEXT("GO!")));
}

